import numpy as np
import matplotlib.pyplot as plt
import cv2
def nothing(x):
    pass
#读取micasense BGR通道数据并合成RGB图
#img = cv2.imread('./img/spec/IMG_0400_1.tif')
img_b=cv2.imread('./img/spec/IMG_0000_1.tif')
img_g=cv2.imread('./img/spec/IMG_0000_2.tif')
img_r=cv2.imread('./img/spec/IMG_0000_3.tif')
#读取一个颜色通道
b = img_b[:,:,0]#实际上这个相机的 0  1  2是一样的
g = img_g[:,:,1]
r = img_r[:,:,2]
rows,cols=g.shape
img=cv2.merge([b,g,r])
cv2.imshow('image_rawdata',img)

G=np.float32([[1,0,4],[0,1,5]]) #平移矩阵  np.float32([[1,0,tx],[0,1,ty]])
B=np.float32([[1,0,-25],[0,1,-2]])
G1=cv2.warpAffine(g,G,(cols,rows))
B1=cv2.warpAffine(b,B,(cols,rows))
img=cv2.merge([B1,G1,r])
cv2.imshow('image_alight',img)
cv2.imwrite('./img/rgb.png',img)
print('img info:')
print('shape:',img.shape,' pixal num:',img.size/10000,'W  dtype:',img.dtype)
zeros = np.zeros(img.shape[:2], dtype = "uint8")
#RGB拆分
#b,g,r=cv2.split(img)
#RGB组合br
#img2=cv2.merge([b,g,r])

ratio=0.0
#cv2.namedWindow('image')
#cv2.createTrackbar('Ratio','image',0,255,nothing)
while(1):
    #cv2.imshow('image',(r*(ratio/255.0))/(b+g+r))
    #cv2.imshow('imager',r)
    #cv2.imshow('imageg',g)
    #cv2.imshow('imageb',b)
    k=cv2.waitKey(1)&0xFF
    if k==27:
        break
    ratio=cv2.getTrackbarPos('Ratio','image')
    #print((1-ratio/255.0))
cv2.destroyAllWindows()